package com.saitron.zhky.provider.health.t;

import cn.hutool.json.JSONUtil;

import java.util.ArrayList;
import java.util.List;

public class Test {

    /*public static void main(String[] args) {
        List<TestChildren> testChildren = new ArrayList<>();
        testChildren.add(new TestChildren(1L, "父元素", "", 0L));
        testChildren.add(new TestChildren(2L, "子元素1", "1", 1L));
        testChildren.add(new TestChildren(3L, "子元素2", "1", 1L));
        testChildren.add(new TestChildren(4L, "子元素2的孙子元素", "1,3", 3L));

        testChildren = TreeNodeUtil.buildTree(testChildren);

        System.out.println(JSONUtil.toJsonStr(testChildren));

        //System.out.println(JSONUtil.toJsonStr(Result.success(testChildren)));
    }*/

    public static void main(String[] args) {
        List<TestChildren> testChildren = new ArrayList<>();
        testChildren.add(new TestChildren(1L, "父元素", "", 0L));
        testChildren.add(new TestChildren(2L, "子元素1", "1", 1L));
        testChildren.add(new TestChildren(3L, "子元素2", "1", 1L));
        testChildren.add(new TestChildren(4L, "子元素2的孙子元素", "1,3", 3L));

        //testChildren = TreeNodeUtil.buildTree(testChildren);

        // 对 3L 进行剪枝,对 1L 进行修改，这个是只保留3L
        //testChildren = TreeNodeUtil.buildTree(testChildren, (item) -> {
        //    if (item.getId().equals(1L)) {
        //        item.setName("更改了 Id 为 1L 的数据名称");
        //    }
        //    return item;
        //}, (item) -> item.getId().equals(3L));

        // 对 3L 进行剪枝,对 1L 进行修改
        testChildren = TreeNodeUtil.buildTree(testChildren, (item) -> {
            if (item.getId().equals(1L)) {
                item.setName("更改了 Id 为 1L 的数据名称");
            }
            return item;
        }, (item) -> !item.getId().equals(3L));

        System.out.println(JSONUtil.toJsonStr(testChildren));

        //System.out.println(JSONUtil.toJsonStr(Result.success(testChildren)));
    }
}
